package com.itcast.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itcast.dao.ReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: lei
 * @version: V1.0
 * @date: 2019/11/30 20:37
 * @description: com.itheima.service
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    ReportMapper reportMapper;

    /**
     * 根据性别查询
     * @return
     */
    @Override
    public List<Map> getSexAndCount() {
         return reportMapper.getSexAndCount();
    }

    /**
     * 根据年龄段查询
     * @return
     */
    @Override
    public List<Map> getAgeAndCount() {
        //查询年龄段和人数
        return reportMapper.getAgeAndCount();
    }

    /**
     * 获取每个月会员增长的
     * @param months
     * @return
     */
    @Override
    public List<Integer> getMemberReport(List<String> months) {
        List<Integer> list = new ArrayList<>();
        for(String month : months){
            //格式：2019.04.31
            Integer count = reportMapper.findMemberCountBeforeDate(month);
            list.add(count);
        }
        return list;
    }
}
